Re: [SQL] Week of year function? - Mailing list pgsql-sql

From Herouth Maoz
Subject Re: [SQL] Week of year function?
Date
Msg-id l03130300b43b2e7ab424@[147.233.159.109]
Whole thread Raw
In response to Re: [SQL] Week of year function?  (Herouth Maoz <herouth@oumail.openu.ac.il>)
List pgsql-sql
At 20:24 +0200 on 25/10/1999, Zot O'Connor wrote:


> Herouth Maoz wrote:
> >
> > At 21:52 +0200 on 22/10/1999, Zot O'Connor wrote:
> >
> > > Is there a function to return the week of the year (0-51)?
> >
> > Seems you only need to divide the day of the year by seven to reach that,
> > don't you?
> >
>
> BTW I ought to offset the year to some standard too since Jan1 is not a
> sunday.  I know Intel starts work week 1 in dec this work year.

That's why I asked whether you only needed to divide by seven. It depends
on your definition of "a week". If you define a week as "seven consecutive
days", then in a year with 365 or 366 days you will always have 53 weeks,
the last of which being a short one. If you define a week as "Monday to
Sunday", or "Sunday to Saturday" (this is culture-dependent), then you may
even have 54 weeks per year (52 full weeks, a weekend in the beginning, and
the beginning of a week in the end - but only in a leap year). This
complicates the calculation a bit. You probably have to subtract the
day-of-week (0-7) oy January first from it, and then subtract the resulting
date from your $1, and divide by 7.

This is true in places where the week's first day is Sunday.

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma




pgsql-sql by date:

Previous
From: John Ridout
Date:
Subject: RE: [SQL] Access and field sizes
Next
From: "Juarez Rudsatz"
Date:
Subject: Re: pgsql-sql-digest V1 #393